<template>
  <d2-container>
    <template slot="header">计量器具列表</template>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-button type="success" size="mini" @click="handleCreate">新增计量器具</el-button>
      </el-form-item>
    </el-form>
    <template>
      <el-table
        :data="tableData"
        style="width: 100%"
        max-height="400">
        <el-table-column
          fixed
          prop="basicId"
          label="编号"
          width="150">
        </el-table-column>
        <el-table-column
          prop="applianceName"
          label="类别代码"
          width="120">
        </el-table-column>
        <el-table-column
          prop="applianceName"
          label="器具名称"
          width="120">
        </el-table-column>
        <el-table-column
          prop="applianceType"
          label="类型"
          width="120">
        </el-table-column>
        <el-table-column
          prop="model"
          label="型号规格"
          width="120">
        </el-table-column>
        <el-table-column
          prop="accuracyDegree"
          label="准确度等级"
          width="120">
        </el-table-column>
        <el-table-column
          prop="measureRange"
          label="测量范围"
          width="120">
        </el-table-column>
        <el-table-column
          prop="departId"
          label="检测部门"
          width="120">
        </el-table-column>
        <el-table-column
          prop="detectionMethod"
          label="检测方式"
          width="120">
        </el-table-column>
        <el-table-column
          prop="certificateJdzq"
          label="检测周期"
          width="120">
        </el-table-column>
        <el-table-column
          prop="detectionFee"
          label="检测费"
          width="120">
        </el-table-column>
        <el-table-column
          prop="isDiscount"
          label="是否可打折"
          width="120">
        </el-table-column>
        <el-table-column
          prop="isVerifyAuthName"
          label="授权鉴定"
          width="120">
        </el-table-column>
        <el-table-column
          prop="isCalibrationAuth"
          label="授权校准"
          width="120">
        </el-table-column>
        <el-table-column
          prop="isCnasAuth"
          label="授权cans"
          width="120">
        </el-table-column>
        <el-table-column
          prop="isTestAuth"
          label="授权检测"
          width="120">
        </el-table-column>
        <el-table-column
          prop="isForce"
          label="是否强检"
          width="120">
        </el-table-column>
        <el-table-column
          prop="status"
          label="是否启用"
          width="120">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="120">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="editRow(scope.$index, tableData)"
              type="text"
              size="small">
              编辑
            </el-button>
            <el-button
              @click.native.prevent="deleteRow(scope.$index, tableData)"
              type="text"
              size="small">
              移除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="pagination.currentPage"
      :page-size="pagination.pageSize"
      :total="pagination.totalPage"
      layout="total, prev, pager, next, jumper">
    </el-pagination>
  </d2-container>
</template>
<script>
import api from '@/api'

export default {
  name: 'base-utensil-list',
  created () {
    this.getUtensilTypeList()
    this.getDepartmentList()
    this.getdata()
  },
  methods: {
    async getUtensilTypeList () {
      var res = await api.BASE_UTENSIL_TYPE_LIST({
        pageNo: 1,
        pageSize: 500
      })
      this.utensilTypeList = res.list
    },
    async getDepartmentList () {
      var res = await api.OA_DEPARTMEN_LIST({
        departName: '',
        departShortName: '',
        pageNo: 1,
        pageSize: 10
      })
      this.departmentList = res.list
    },
    async getdata () {
      var res = await api.BASE_UTENSIL_LIST({
        pageNo: 1,
        pageSize: 10
      })
      this.count = res.total
      this.tableData = res.list
    },
    handleCurrentChange (val) {
      this.currentPage = val
    },
    handleCreate () {
      this.$router.push({ name: 'base-utensil-create' })
    },
    handleEdit (index, row) {
      this.$router.push({ name: 'base-utensil-create', params: { id: row.id } })
    },
    handelDelete (index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.OA_USER_DELETE()
        this.getData()
      })
    }
  },
  data () {
    return {
      departMentList: [],
      utensilTypeList: [],
      pagination: {
        currentPage: 1,
        totalPage: 0,
        pageSize: 20
      },
      tableData: []
    }
  }
}
</script>
